<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .ad{
            position: relative;
            width: 400px;
            height: 400px;
            background-color: pink;
            margin: 5px;
        }
        .ad .close{
            position: absolute;
            top: 5px;
            right: 5px;
            width: 20px;
            height: 20px;
            border: 1px solid red;
            text-align: center;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="ad1">1</div>
    <div class="ad">2
        <h3 class="close">X</h3>
        <h3 class="close2">y</h3>
        <h3 class="close3">z</h3>
    </div>

    <script>
        const clo=document.querySelector('.close');
        clo.addEventListener('click',function(){
            //事件处理函数
            // const ad=document.querySelector('.ad');
            // ad.style.display='none';
            clo.parentElement.style.display='none';
        },false);
        // const ad=document.querySelector('.ad');
        console.log(clo.parentNode);
        console.log(clo.parentElement);

        const ad=document.querySelectorAll('.ad');
        console.log(ad[0].childNodes);
        console.log(ad[0].children);

        // console.log(ad[1].childNodes);
        // console.log(ad[1].children);

        const ad1=document.querySelector('.ad1');
        console.log(ad1.nextElementSibling.children);
    </script>

    <button>创建节点</button>
    <script>
        const btn=document.querySelector('button');
        btn.addEventListener('click',function(){
            //点击按钮创建节点并显示到网页中
            const box=document.createElement('div');
            box.innerHTML='这是新创建的box';
            //向当前节点的哥哥节点追加一个div(box)
            btn.previousElementSibling.appendChild(box);
        })
    </script>
</body>
</html>